package com.example.financeapi.service.impl;

import com.example.financeapi.entity.FNewdebt;
import com.example.financeapi.mapper.FNewdebtMapper;
import com.example.financeapi.service.FNewdebtService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 新债申购表(FNewdebt)表服务实现类
 *
 * @author Alvin
 * @since 2020-03-31 12:04:51
 */
@Service
public class FNewdebtServiceImpl implements FNewdebtService {
    public static final String CACHE_KEY = "Newdebt-cache";
    @Resource
    private FNewdebtMapper fNewdebtMapper;

    /**
     * 通过ID查询单条数据 第二次访问会取缓存
     * @param id 主键
     * @return 实例对象
     */
    @Override
    //@Cacheable(cacheNames = CACHE_KEY ,key = "#id")
    public FNewdebt queryById(String id) {
        return this.fNewdebtMapper.queryById(id);
    }

    /**
     * 查询新债发行列表
     * @param map
     * @return
     */
    @Override
    public List<FNewdebt> getFNewdebtList(Map<String,Object> map) {
        return this.fNewdebtMapper.getFNewdebtList(map);
    }

    /**
     * 新增数据
     *
     * @param fNewdebt 实例对象
     * @return 实例对象
     */
    @Override
    public FNewdebt insert(FNewdebt fNewdebt) {
        this.fNewdebtMapper.insert(fNewdebt);
        return fNewdebt;
    }

    /**
     * 修改数据 更新缓存
     * @param fNewdebt 实例对象
     * @return 实例对象
     */
    @Override
    //@CachePut(cacheNames = CACHE_KEY ,key = "#fNewdebt.id")
    public FNewdebt update(FNewdebt fNewdebt) {
        this.fNewdebtMapper.update(fNewdebt);
        return this.queryById(fNewdebt.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    //@CacheEvict(cacheNames = CACHE_KEY ,key = "#id")
    public int deleteById(String id) {
        return fNewdebtMapper.deleteById(id);
    }
}